
int valueToInt(dynamic value, {defaultValue = 0}) {
  if (value is int) {
    return value;
  } else if (value is double) {
    return value.toInt();
  } else if (value is String) {
    if (value.isEmpty) {
      return 0;
    }
    try {
      return int.parse(value);
    } catch (_) {
      return 0;
    }
  } else {
    return defaultValue;
  }
}

String valueToString(dynamic value,{defaultValue = ""}) {
  if (value is String) {
    return value;
  } else if (value is int) {
    return value.toString();
  } else {
    return defaultValue;
  }
}

double valueToDouble(dynamic value) {
  try {
    if (value is double) {
      return value;
    } else if (value is String) {
      if (value == "") {return 0;}
      return double.parse(value);
    } else if (value is int) {
      return value.toDouble();
    } else {
      return 0.0;
    }
  } catch (e) {
    return 0.0;
  }
}

bool valueToBool(dynamic value,{defaultValue = false}) {
  if (value is bool) {
    return value;
  } else if (value is String) {
    return value == 'true';
  } else if (value is int) {
    return value != 0;
  } else {
    return false;
  }
}

Map valueToMap(dynamic value) {
  if (value is Map) {
    return value;
  } else {
    return {};
  }
}

List<dynamic> valueToList(dynamic value) {
  if (value is List<dynamic>) {
    return value;
  } else {
    return [];
  }
}

DateTime valueToDateTime(dynamic value) {
  if (value is DateTime) {
    return value;
  } else if (value is String) {
    return DateTime.parse(value);
  } else {
    return DateTime.now();
  }
}



